// MainFrm.h : interface of the CMainFrame class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once

#include <atlbase.h>
#include <atlstr.h>
#include <atlapp.h>

extern CAppModule _Module;

#include <atlframe.h>
//#include <string>
#include "atlctrls.h"
#include "atlctrlw.h"

#define _WTL_NO_CSTRING
#include <atlmisc.h>

#include "ToolbarHelper.h"
#include "PHScroll.h"
#include <atlsplit.h>
#include <atlctrlx.h>
#include "..\PHQuery\resource.h"

#include <shobjidl.h>
#include <shlobj.h>

#include <atlcrack.h>
#include "gdiplus.h"
//#include "PHSplitDlg.h"
#include "MultiPaneStatusBarEx.h"

// wParam = current progress. lParam = total progress.
#define UWM_DOWNLOAD_PROGRESS   (WM_APP)

class CMainFrame : public CFrameWindowImpl<CMainFrame>, 
		public CMessageFilter, public CToolBarHelper<CMainFrame>/*, public CIdleHandler*/
{
public:

	CComboBox m_Combo;
CCommandBarCtrl m_CmdBar;
PHScroll phs;
PHTimeInfo phti;
CHorSplitterWindow m_wndHorzSplit;
//CSplitterWindow m_vSplit;
//PHSplitDlg phexec;
CMPSBarWithProgress m_sBar; //additonal progress for XP

ULONG_PTR           gdiplusToken;
	DECLARE_FRAME_WND_CLASS(NULL, IDR_MAINFRAME)

	virtual BOOL PreTranslateMessage(MSG* pMsg)
	{
		if(CFrameWindowImpl<CMainFrame>::PreTranslateMessage(pMsg))
			return TRUE;

		return phs.PreTranslateMessage(pMsg);
	}

void OnToolBarCombo(HWND hWndCombo, UINT nID, int nSel, LPCTSTR lpszText, DWORD dwItemData){}
/*BEGIN_UPDATE_UI_MAP(CMainFrame)
UPDATE_ELEMENT(ID_QUERY_SHOWLONGPROCESSES, UPDUI_MENUPOPUP)
	END_UPDATE_UI_MAP()*/

	BEGIN_MSG_MAP(CMainFrame)
		//MESSAGE_HANDLER_EX(m_uTaskbarBtnCreatedMsg, OnTaskbarBtnCreated)
		MESSAGE_HANDLER(WM_CREATE, OnCreate)
		MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
		COMMAND_ID_HANDLER(ID_FILE_EXIT, OnFileExit)
		COMMAND_ID_HANDLER(ID_HELP_ABOUT,OnHelpAbout)
		//COMMAND_ID_HANDLER(ID_PH_USER,OnUser)
		COMMAND_ID_HANDLER(ID_PH_HELP,URLHelp);
		COMMAND_ID_HANDLER(ID_VIEW_KEY,OnViewKey)
		COMMAND_ID_HANDLER(ID_BUTTON40092,GoToMostRecent)
		COMMAND_ID_HANDLER(ID_PROCESS_VIEWSELECTED,OnProcessViewSelected)
		COMMAND_ID_HANDLER(ID_IMAGES_RUNSELECTED,OnExecRunSel)
		COMMAND_ID_HANDLER(ID_IMAGES_OPENCONTAININGFOLDER,OnExecOCF)
		COMMAND_ID_HANDLER(ID_CONTEXT_GOTOSTART,OnGotoBegin)
		COMMAND_ID_HANDLER(ID_CONTEXT_GOTOEND,OnGotoEnd)
		 MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
		 COMMAND_ID_HANDLER(ID_BUTTON40069,PHTBQry)
		COMMAND_ID_HANDLER(ID_BUTTON40071,PHTBLeft)
		COMMAND_ID_HANDLER(ID_BUTTON40070,PHTBRight)
		 MESSAGE_HANDLER(UWM_DOWNLOAD_PROGRESS, NotifyGUI)
		 COMMAND_ID_HANDLER(ID_CONTEXT_FILTERONTHISUSER,OnFilterUser)
		 COMMAND_ID_HANDLER(ID_CONTEXT_FILTEREXECUTABLE,OnFilterExecutable)
		 COMMAND_ID_HANDLER(ID_CONTEXT_CLEAREXECUTABLEFILTER,OnClearExecFilter)
		 COMMAND_ID_HANDLER(ID_CONTEXT_CLEARUSERFILTER,OnClearUserFilter)
		 COMMAND_ID_HANDLER(ID_BUTTON40093,OnClearAllFilter)		 		
		CHAIN_MSG_MAP(CFrameWindowImpl<CMainFrame>)
		CHAIN_MSG_MAP(CToolBarHelper<CMainFrame>)
	END_MSG_MAP()

// Handler prototypes (uncomment arguments if needed):
//	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
//	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

	LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);

	LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
	{
		Gdiplus::GdiplusShutdown(gdiplusToken);
		// unregister message filtering and idle updates
		CMessageLoop* pLoop = _Module.GetMessageLoop();
		ATLASSERT(pLoop != NULL);
		pLoop->RemoveMessageFilter(this);

		bHandled = FALSE;
		return 1;
	}

	LRESULT OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
		PostMessage(WM_CLOSE);
		return 0;
	}

LRESULT NotifyGUI (UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnHelpAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
//LRESULT OnUser(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT PHTBQry(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT PHTBLeft(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT PHTBRight(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnViewKey(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT GoToMostRecent(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnProcessViewSelected(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnExecRunSel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnExecOCF(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled);
//LRESULT OnUserDataSelected( int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/ );
LRESULT OnGotoBegin(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnGotoEnd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT URLHelp(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnFilterUser(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnFilterExecutable(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnClearUserFilter(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnClearExecFilter(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnClearAllFilter(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
//void RF1(std::string where);
void LeftRight(WPARAM wParam);
void ParseQry();
void DateTimeQry();
//void FillPHExec();
//LRESULT CALLBACK CMainFrame::SubClassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) ;

/*LRESULT OnTaskbarBtnCreated ( UINT uMsg, WPARAM wParam, LPARAM lParam );
protected:
	 CComPtr<ITaskbarList3> m_pTaskbarList;*/
 
private:
  static const UINT m_uTaskbarBtnCreatedMsg;
};
 



class KeyCtrl : public CDialogImpl<KeyCtrl>
{
public:
	enum { IDD = IDD_KEY };
	BEGIN_MSG_MAP(KeyCtrl)
		COMMAND_ID_HANDLER(IDOK, OnCloseCmd)
	END_MSG_MAP()
	LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
		EndDialog(wID);
		return 0;
	}	
};